import unittest
import requests
import utils
from api.tpshopAPI_Login import LoginAPI
class TestLogin(unittest.TestCase):
    my_session=None

    @classmethod
    def setUpClass(cls) -> None:
        cls.my_session = requests.Session()
        cls.loginApi=LoginAPI()
    @classmethod
    def tearDownClass(cls) -> None:
        cls.my_session.close()
    #普通方法,登录成功
    def test01_login_ok(self):
        re_data = {'username': '13800138006',
                'password': '123456',
                'verify_code': '8888'}
        resp=self.loginApi.login(self.my_session,re_data)
        print(resp.json())
        # self.assertEqual(200,resp.status_code)
        # self.assertEqual(1,resp.json().get('status'))
        # self.assertIn('登陆成功',resp.json().get('msg'))
        utils.common_assert(self,resp,200,1,'登陆成功')
    #普通方法,账号不存在
    def test02_username_not_exists(self):
        re_data = {'username': '15688574863',
                'password': '123456',
                'verify_code': '8888'}
        resp=self.loginApi.login(self.my_session,re_data)
        print(resp.json())
        # self.assertEqual(200,resp.status_code)
        # self.assertEqual(-1,resp.json().get('status'))
        # self.assertIn('账号不存在',resp.json().get('msg'))
        utils.common_assert(self,resp,200,-1,'账号不存在')
    #普通方法,密码错误
    def test03_pwd_error(self):
        re_data = {'username': '13800138006',
                'password': '1234*7891',
                'verify_code': '8888'}
        resp=self.loginApi.login(self.my_session,re_data)
        print(resp.json())
        # self.assertEqual(200,resp.status_code)
        # self.assertEqual(-2,resp.json().get('status'))
        # self.assertIn('密码错误',resp.json().get('msg'))
        utils.common_assert(self,resp,200,-2,'密码错误')